package com.hxd.otc.module.my.presenter;

import android.support.annotation.NonNull;

import com.hxd.otc.base.BaseBean;
import com.hxd.otc.base.BaseRecyclerPresenter;
import com.hxd.otc.common.enums.TradeType;
import com.hxd.otc.module.my.adapter.AdAdapter;
import com.hxd.otc.module.my.bean.AdvertBean;
import com.hxd.otc.module.my.bean.BaseListBean;
import com.hxd.otc.module.my.contract.AdContract;
import com.hxd.otc.module.my.model.OtcAdvertModel;
import com.hxd.otc.net.BaseObserver;

import java.util.ArrayList;

/**
 * Created by lzy on 2018/6/11 0011.
 * description ${广告管理列表 Presenter}
 */
public class AdPresenter extends BaseRecyclerPresenter<AdContract.View, AdAdapter, AdvertBean> implements AdContract.Presenter {

    private TradeType mTradeType;

    private final OtcAdvertModel mOtcAdvertModel;

    public AdPresenter(AdContract.View view) {
        super(view);
        mOtcAdvertModel = OtcAdvertModel.getInstance();
    }

    @Override
    public void loadData(final boolean isRefresh) {
        mOtcAdvertModel.getMyAdvertList(mTradeType.getValue(), mPageIndex, getPageSize(), new BaseObserver<BaseListBean<AdvertBean>>() {
            @Override
            public void onNext(@NonNull String msg, @NonNull BaseListBean<AdvertBean> listBean) {
                onLoadDataSuccess(isRefresh, listBean.getList());
            }

            @Override
            public void onError(int errType, @NonNull String errMessage) {
                onLoadDataFail(isRefresh, errMessage);
            }
        }, mView.<BaseBean<BaseListBean<AdvertBean>>>bindAutoDispose());
    }

    @Override
    public void revokeAdvert(final String id,boolean isNosenseOrder) {
        mOtcAdvertModel.revokeAdvert(id, isNosenseOrder,new BaseObserver<String>() {
            @Override
            public void onNext(@NonNull String msg, @NonNull String s) {
                mView.revokeAdvertSuccess(id);
            }

            @Override
            public void onError(int errType, @NonNull String errMessage) {
                mView.showToast(errMessage);
            }
        }, mView.<BaseBean<String>>bindAutoDispose());
    }

    @Override
    public TradeType getExType() {
        return mTradeType;
    }

    @Override
    public void setExType(TradeType exType) {
        this.mTradeType = exType;
    }
}
